package com.droidathletics.boundary.microcycles;

import java.util.Iterator;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.style.BackgroundColorSpan;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import com.droidathletics.R;
import com.droidathletics.boundary.MainMenu;
import com.droidathletics.entity.TypeTraining;

public class CreateMicrocyclesTrVolume extends Activity {

    
	@Override
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.create_microcycle_training);
        
        typeTrainingSp = (Spinner) findViewById(R.id.spinnerTypeTraining);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
					        									android.R.layout.simple_spinner_item, 
					        									CreateMicrocycles.trainingValues);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        typeTrainingSp.setAdapter(adapter);
        
        volumeField = (EditText) findViewById(R.id.fieldTrainingVolume);
        
        saveButton = (Button) findViewById(R.id.buttonCMicroTrainingSave);
        saveButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	String selectedTraining = typeTrainingSp.getSelectedItem().toString();
            	Iterator<TypeTraining> iter = CreateMicrocycles.trainings.iterator();
            	while(iter.hasNext()){
            		TypeTraining tempTraining = iter.next();
            		if(selectedTraining==tempTraining.getName()){
            			tempTraining.setVolume(Double.parseDouble(volumeField.getText().toString()));
            			CreateMicrocycles.setAdapterSpinner();
            			finish();
            			return;
            		}
            	}
            }
        });
	}
	
	@Override
    public void onBackPressed() {
		finish();
	    return;
    }
	private Spinner typeTrainingSp;
	private EditText volumeField;
	private Button saveButton;
}
